//
//  FQOrganizationTableViewCell.swift
//  SwiftProject
//
//  Created by 董駸 on 2022/8/19.
//

import UIKit
import AttributedString

class FQOrganizationTableViewCell: BaseTableViewCell {

    let imageV = UIImageView()
    let titleLb = QMUILabel(font: .rSFont(15~), textColor: .color51)
    let rateLb = QMUILabel(font: .rSFont(16~), textColor: .color51)
    let limitLb = QMUILabel(font: .rSFont(16~), textColor: .qmui_color(withHexString: "DE642C")!)
    
    var model : FQOrganizationModel! {
        didSet {
            imageV.backgroundColor = .blue
            titleLb.text = "我的"
            var rateStr : ASAttributedString = """
            0.45%\n日利率
            """
            rateStr.add(attributes: [.foreground(.color149), .font(.rSFont(13~))], checkings: [.range(rateStr.value.string.asNSString.range(of: "日利率"))])
            rateLb.attributed.text = rateStr
            
            var limitStr : ASAttributedString = """
            ¥ 200000\n最高可借额度
            """
            limitStr.add(attributes: [.foreground(.color149), .font(.rSFont(13~))], checkings: [.range(limitStr.value.string.asNSString.range(of: "最高可借额度"))])
            limitLb.attributed.text = limitStr
        }
    }
    
    override var contentViewInset: UIEdgeInsets {
        UIEdgeInsets(top: 16, left: 10, bottom: 0, right: 10)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        backgroundColor = .white
        layer.cornerRadius = 8
        clipsToBounds = true
        
        imageV.layer.cornerRadius = 4
        imageV.clipsToBounds = true
        contentView.addSubview(imageV)
        
        imageV.snp.makeConstraints { make in
            make.size.equalTo(32~)
            make.left.equalTo(16~)
            make.top.equalTo(14~)
        }
        
        contentView.addSubview(titleLb)
        titleLb.snp.makeConstraints { make in
            make.left.equalTo(imageV.snp.right).offset(12)
            make.centerY.equalTo(imageV)
            make.right.equalToSuperview().offset(-10)
        }
        
        let iconV = UIImageView(imageString: "icon_celllIcon")
        contentView.addSubview(iconV)
        
        iconV.snp.makeConstraints { make in
            make.right.bottom.equalToSuperview()
        }
        
        let button = QMUILabel(font: .rSFont(14~), textColor: .colorMain)
        button.text = "了解详情"
        button.layer.borderWidth = 1
        button.layer.borderColor = UIColor.colorMain.cgColor
        button.layer.cornerRadius = 4
        button.textAlignment = .center
        contentView.addSubview(button)
        
        button.snp.makeConstraints { make in
            make.right.equalTo(-14)
            make.size.equalTo(CGSize(width: 76, height: 28)~)
            make.bottom.equalTo(-16)
        }
        
        limitLb.numberOfLines = 0
        limitLb.textAlignment = .center
        contentView.addSubview(limitLb)
        
        limitLb.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.bottom.equalTo(-10~)
        }
        
        rateLb.numberOfLines = 0
        rateLb.textAlignment = .center
        contentView.addSubview(rateLb)
        
        rateLb.snp.makeConstraints { make in
            make.left.equalTo(limitLb.snp.right).offset(57)
            make.bottom.equalTo(-10~)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
